<template>
  <view class="loading-example">
    <view class="header">
      <text class="title">Loading 组件示例</text>
    </view>
    
    <!-- 基本用法 -->
    <view class="section">
      <text class="section-title">基本用法</text>
      <view class="demo-item">
        <loading :show="basicLoading" text="基本加载"></loading>
        <button @click="toggleBasicLoading" class="demo-btn">
          {{ basicLoading ? '隐藏' : '显示' }}基本Loading
        </button>
      </view>
    </view>
    
    <!-- 不同样式 -->
    <view class="section">
      <text class="section-title">不同样式</text>
      <view class="demo-grid">
        <view class="demo-item">
          <loading :show="true" type="default" text="默认旋转"></loading>
        </view>
        <view class="demo-item">
          <loading :show="true" type="spinner" text="圆点旋转"></loading>
        </view>
        <view class="demo-item">
          <loading :show="true" type="pulse" text="脉冲"></loading>
        </view>
        <view class="demo-item">
          <loading :show="true" type="wave" text="波浪"></loading>
        </view>
      </view>
    </view>
    
    <!-- 不同尺寸 -->
    <view class="section">
      <text class="section-title">不同尺寸</text>
      <view class="demo-grid">
        <view class="demo-item">
          <loading :show="true" size="small" text="小尺寸"></loading>
        </view>
        <view class="demo-item">
          <loading :show="true" size="medium" text="中等尺寸"></loading>
        </view>
        <view class="demo-item">
          <loading :show="true" size="large" text="大尺寸"></loading>
        </view>
      </view>
    </view>
    
    <!-- 自定义样式 -->
    <view class="section">
      <text class="section-title">自定义样式</text>
      <view class="demo-item">
        <loading 
          :show="customLoading" 
          type="pulse" 
          size="large"
          text="自定义样式"
          textColor="#007aff"
          :textSize="32"
          backgroundColor="rgba(0, 0, 0, 0.8)"
        ></loading>
        <button @click="toggleCustomLoading" class="demo-btn">
          {{ customLoading ? '隐藏' : '显示' }}自定义Loading
        </button>
      </view>
    </view>
    
    <!-- 全屏显示 -->
    <view class="section">
      <text class="section-title">全屏显示</text>
      <view class="demo-item">
        <button @click="showFullscreenLoading" class="demo-btn">显示全屏Loading</button>
      </view>
    </view>
    
    <!-- 全屏loading -->
    <loading 
      :show="fullscreenLoading" 
      :fullscreen="true" 
      type="spinner"
      text="全屏加载中..."
      textColor="#ffffff"
      backgroundColor="rgba(0, 0, 0, 0.8)"
    ></loading>
  </view>
</template>

<script>
import Loading from './loading.vue'

export default {
  components: {
    Loading
  },
  data() {
    return {
      basicLoading: false,
      customLoading: false,
      fullscreenLoading: false
    }
  },
  methods: {
    toggleBasicLoading() {
      this.basicLoading = !this.basicLoading
    },
    toggleCustomLoading() {
      this.customLoading = !this.customLoading
    },
    showFullscreenLoading() {
      this.fullscreenLoading = true
      // 3秒后自动隐藏
      setTimeout(() => {
        this.fullscreenLoading = false
      }, 3000)
    }
  }
}
</script>

<style lang="scss" scoped>
.loading-example {
  padding: 30rpx;
  background-color: #f5f5f5;
  min-height: 100vh;
}

.header {
  text-align: center;
  margin-bottom: 40rpx;
  
  .title {
    font-size: 36rpx;
    font-weight: bold;
    color: #333;
  }
}

.section {
  background-color: #ffffff;
  border-radius: 16rpx;
  padding: 30rpx;
  margin-bottom: 30rpx;
  
  .section-title {
    font-size: 32rpx;
    font-weight: bold;
    color: #333;
    margin-bottom: 30rpx;
    display: block;
  }
}

.demo-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20rpx;
}

.demo-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 30rpx;
}

.demo-btn {
  background-color: #007aff;
  color: #ffffff;
  border: none;
  border-radius: 8rpx;
  padding: 20rpx 40rpx;
  font-size: 28rpx;
  
  &:active {
    background-color: #0056cc;
  }
}
</style> 